var loading = false; //状态标记+
var app = new Vue({
    el: '#app',
    data: {
        tabs: ['展会光影', '展会专访', '国内展会', '国际展会'],
        tabContents: ["内容一", "内容二", "内容三", '没有内容了'],
        recent: [
        {
            name: '所有时间',
            id: 0
        },    
        {
            name: '最近一月',
            id: 1
        }, {
            name: '最近两月',
            id: 2
        }, ],
        num: 0,
        time: 10,
        listTab: [],
        listSwiper: [],
        hideing: true,
        typeindex: 0,
        userId: 0,
        objectId: 0,
        pageIndex: 1,
        pageSize: 10,
        Type: 0,
    },
    created: function() {
        FastClick.attach(document.body);
        $(document.body).infinite();

        var objectId = $.getPara('type');
        this.typeindex = objectId;

        if ($.getPara("userId") != "") {
            var userId = $.getPara("userId");
            this.userId = userId;
            $.setStorage("userId", userId)
        } else {
            if ($.getStorage("userId") && $.getStorage("userId") != "") {
                var userId = parseInt($.getStorage("userId"));
                this.userId = userId
            }
        }
        this.num = objectId;
        if(this.typeindex == 0){//展会光影  、
            //轮播图类型 1首页、2学院、3协会、4媒体、5印厂、6分站首页、7最新资讯、8推荐资讯、9展会1，10展会2，11展会光与影、12展会专访、13国内展会、14国际专访
            this.getBanner(11);
        }else if(this.typeindex == 1){
            this.getBanner(12);
        }else if(this.typeindex == 2){
            this.getBanner(13);
        }else{
            this.getBanner(14);
        }
        this.getData(this.typeindex, this.Type, this.pageIndex, this.pageSize)
    },
    mounted() {
        var that = this;
        this.$nextTick(function() {
            $(document.body).infinite().on("infinite", function() {
                if (loading) return;
                loading = true;
                that.hideing = false;
                setTimeout(function() {
                    var pageIndex = that.pageIndex;
                    pageIndex++;
                    that.pageIndex = pageIndex;
                    that.getData(that.typeindex, that.Type, that.pageIndex, that.pageSize);
                    loading = false;
                }, 1500)
            })
        })
    },
    methods: {
        backTop: function() {
            window.history.go(-1)
        },
        //获得轮播图
        getBanner(types) {
            var that = this;
            $.ajax({
                type: "GET",
                url: "/api/banner-ad/banner/index",
                dataType: 'json',
                data: {
                    type: types,
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data;
                    if (list.length > 0) {
                        var original = that.listSwiper;
                        var array = original.concat(list);
                        that.listSwiper = array
                     
                    } else {//loading = true;
                    }
                    that.$nextTick(function() {
                        var swiper = new Swiper('#exList-banner',{
                            autoplay: 3000,
                            loop: true,
                            pagination: '.exList-pagination',
                            autoplayDisableOnInteraction: false,
                        })
                    })
                } else {
                    $.toast(res.msg, "text")
                }
            })
        },
        //展会数据
        getData(types, timeType, pageIndex, pageSize) {
            var that = this;
            types++;
            $.ajax({
                type: "GET",
                url: "/api/exhibition/list",
                dataType: 'json',
                data: {
                    id: that.id,
                    type: types,
                    timeType: timeType,
                    pageIndex: pageIndex,
                    pageSize: pageSize
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data.list;
                    if (list.length > 0) {
                        var original = that.listTab;
                        var array = original.concat(list);
                        that.listTab = array;
                        // loading = false;
                    } else {
                        loading = true;
                        // $.toast("没有更多了...", "text");
                    }
                    that.hideing = true;
                } else {
                    $.toast(res.msg, "text");
                    //loading = false;
                }
            })
        },
        //展会类型tabs
        getTab(index) {
            loading = false;
            this.num = index;
            this.time = 10;
            var type = index;
            this.typeindex = type;
            this.pageIndex = 1;
            this.listTab = [];
            this.listSwiper = [];
            this.getBanner(index + 11);
            this.Type = 0;
            this.getData(this.typeindex, this.Type, this.pageIndex, this.pageSize)
        },
        getTime(type, index) {
            if (type != this.Type) {
                this.Type = index;
                this.pageIndex = 1;
                this.listTab = [];
                this.getData(this.typeindex, this.Type, this.pageIndex, this.pageSize);
                this.time = index + 10
            }
        },
        urlHref(item) {
            var para = {};
            para.title = "展会详情";
            para.type = "exhibitionDetails";
            para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id=' + item.id;
            if (this.userId > 0) {
                para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id=' + item.id + "&userId=" + this.userId
            }
            if (/(Android)/i.test(navigator.userAgent)) {
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                window.webkit.messageHandlers.appPush.postMessage(para)
            } else {
                window.location.href = para.url;
                alert("PC浏览器")
            }
        },
        urlHref_banner(item) {
            var para = {};
            para.title = "展会详情";
            para.type = "exhibitionDetails";
            if(item.url_type == 2 ){
                if (this.userId > 0) {
                    para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id=' + item.url_value + "&userId=" + this.userId
                }else{
                    para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id=' + item.url_value + "&userId=0";
                }
                if (/(Android)/i.test(navigator.userAgent)) {
                    jsAndroid.appPush(JSON.stringify(para))
                } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                    window.webkit.messageHandlers.appPush.postMessage(para)
                } else {
                    window.location.href = para.url;
                    alert("PC浏览器")
                }
            }
            
        }
    }
})
